package com.vx.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import com.vx.ratingTool.Player;
import com.vx.ratingTool.bo.PlayerBOimpl;
import com.vx.ratingTool.dao.PlayerDAOimpl;

@Controller
@RequestMapping("/createCustomPlayer")
public class CreateCustomPlayerController {

	private PlayerDAOimpl playerDAO;
	private PlayerBOimpl playerBO;

	public PlayerDAOimpl getPlayerDAOimpl() {
		return playerDAO;
	}

	@Autowired
	public void setPlayerDAOimpl(PlayerDAOimpl playerDAO) {
		this.playerDAO = playerDAO;
	}

	public PlayerBOimpl getPlayerBO() {
		return playerBO;
	}

	@Autowired
	public void setPlayerBO(PlayerBOimpl playerBO) {
		this.playerBO = playerBO;
	}

	// private SessionFactory sessionFactory;

	@RequestMapping(method = RequestMethod.GET)
	public void SetupForm() {

	}

	@RequestMapping(method = RequestMethod.POST)
	public String CreatePlayers(@RequestParam("id") int id, @RequestParam("name") String name, @RequestParam("skill") int skill,
			@RequestParam("rating") int rating, @RequestParam("placements") int placements, Model model) {

		playerBO.save(new Player(id, name, skill, rating, placements, 0));

		model.addAttribute("success", "Player #" + id + " <" + playerBO.findById(id).getName() + "> created!");

		return "createCustomPlayer";
	}

}
